﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Stock.Model.WX
{
      public class MessageFactory
      {
            public static BaseMessage CreateMessage(string xml)
            {
                  XElement xdoc = XElement.Parse(xml);
                  var msgtype = xdoc.Element("MsgType").Value.ToUpper();
                  MsgType type = (MsgType)Enum.Parse(typeof(MsgType), msgtype);
                  switch (type)
                  {
                        case MsgType.TEXT: return ConvertXML.ConvertObj<TextMessage>(xml);
                        case MsgType.IMAGE: return ConvertXML.ConvertObj<ImgMessage>(xml);
                        case MsgType.VIDEO: return ConvertXML.ConvertObj<VideoMessage>(xml);
                        case MsgType.VOICE: return ConvertXML.ConvertObj<VoiceMessage>(xml);
                        case MsgType.LINK:
                              return ConvertXML.ConvertObj<LinkMessage>(xml);
                        case MsgType.LOCATION:
                              return ConvertXML.ConvertObj<LocationMessage>(xml);
                        //case MsgType.EVENT://事件类型
                        //      {

                        //      }
                        //      break;
                        default:
                              return ConvertXML.ConvertObj<BaseMessage>(xml);
                  }
            }
      }
}
